//
//  UserLevelView.h
//  HelloCpp
//
//  Created by apple  on 13-6-16.
//
//

#ifndef __XIAOLIAN__UserLevelView__
#define __XIAOLIAN__UserLevelView__

#include "cocos2d.h"
#include "BCSManager.h"
#include "cocos-ext.h"
#include "AccountManager.h"
#include <vector>

USING_NS_CC;
USING_NS_CC_EXT;


class UserLevelView : public CCScene, public BCSDelegate, public CCScrollViewDelegate, public AccountManagerDelegate
{
public:
	UserLevelView():m_nItemsCount(0), m_orderType(0){};
	virtual ~UserLevelView(){};

	static UserLevelView* create();

	virtual void onEnter();
	virtual void onExit();

	bool init();

	void menuItemClick(CCObject* sender);
	void update(float dt);

	void addItem(const char* fileName, const char* userName);

	void willDownloadFile(const char* filename);
	void willUploadFile(const char* filename);

	void didDownloadFile(const char* filename);
	void didUploadFile(const char* filename);

	void myScoreChanged(int score);
	void updateMyScore();

	void cleanItems();
	void orderByNew(int iStart, int iEnd);
	void orderByEarly(int iStart, int iEnd);
	void orderByLowScore(int iStart, int iEnd);
	void orderByHighScore(int iStart, int iEnd);
	void orderByGood(int iStart, int iEnd);
	void orderByBad(int iStart, int iEnd);
	void orderByMy(int iStart, int iEnd);

	void download(const char* sql, int iStart, int iEnd);
	void download(const std::map<std::string, LevelInfo>& levelInfos, const std::vector<std::string>& orderNames);

	virtual void scrollViewDidScroll(CCScrollView* view);
	virtual void scrollViewDidZoom(CCScrollView* view);
	//add by gzy:
	virtual void scrollViewClicked(CCScrollView* view, const CCPoint& posWorld);

protected:
	unsigned int m_nItemsCount;
	std::map<std::string, LevelInfo> m_levelInfos;
	std::vector<std::string> m_orderNames;
	int m_orderType;
};

#endif